package com.example.webjsdemo

import android.os.Bundle
import android.util.Log
import com.huawei.hms.push.HmsMessageService
import com.huawei.hms.push.RemoteMessage

/**
 *
 * Created on 2022/4/7.
 * @author tdq
 */
class DemoHmsMessageService : HmsMessageService() {
    override fun onNewToken(token: String?, bundle: Bundle?) {
        // 获取token
        Log.i("onNewToken", "have received refresh token:$token")

        // 判断token是否为空
        if (!token.isNullOrEmpty()) {
            refreshedTokenToServer(token)
        }
    }

    private fun refreshedTokenToServer(token: String) {
        Log.i("refreshedTokenToServer", "sending token to server. token:$token")
    }

    override fun onMessageReceived(p0: RemoteMessage?) {
        p0?.data?.let { Log.e("onMessageReceived", it) }
    }

}